const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
function InitTime(endtime){
    var dd,hh,mm,ss = null;
    var time = (new Date(endtime).getTime() - new Date().getTime())/1000;
    if(time<=0){
        return 0
    }else{
        dd = Math.floor(time / 60 / 60 / 24);
        hh = Math.floor((time / 60 / 60) % 24);
        mm = Math.floor((time / 60) % 60);
        ss = Math.floor(time  % 60);
        var str = dd+"天"+hh+":"+mm+":"+ss;
        return str;
    }
}
Page({
  data: {
    id:'',
    orderDetaildata:'',
    logisticsdata:'',
  },
  
  onLoad: function (options) {
    if(options.id){
      this.setData({
        id:options.id
      })
    }
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },
  onShow(){
    if(this.data.id){
      this.setData({
        orderDetaildata:'',
        
      })
      this.orderDetail()
    }

  },
  service(){
    wx.redirectTo({
      url: '/pages/service/service?id='+this.data.id
    })
  },
  //复制
  handleCopy(e){
    
    let type=e.target.dataset.type
    let copyVal=''
     
    if(!type){
      return
    }
    if(type=='order'){
      copyVal=this.data.orderDetaildata.orderNumber
    }
    if(type=='logistics'){
      copyVal=this.data.orderDetaildata.logisticsNumber
    }
    wx.setClipboardData({
      data:copyVal,
      success:function (res) {
        wx.getClipboardData({
          success:function (res) {
            wx.showToast({
              title: '复制成功',
            })
             
          }
 
        })
 
      }
 
    })
  },
  orderDetail(){
    var that=this;
    Controller.orderdetail({orderNumber:that.data.id}).then(res=>{
      if(res.data){
        that.setData({
          orderDetaildata:res.data.baseData
        })
        // 0待支付，1已支付积分待支付现金，2已支付待发货，3已发货待收货，4已收货，5已评价，-1退单，-2支付费用失败,-3,订单已关闭

        if(this.data.orderDetaildata.orderStatus==3 || this.data.orderDetaildata.orderStatus==4){
          this.logistics()
        }
        
      }
    })
  },

  logistics(){
    Controller.logistics({orderNumber:this.data.id}).then(res=>{
      if(res.data.baseData){
        this.setData({
          logisticsdata:res.data.baseData,
        })
      }
    })
  },
  

})